/**
 * $Id: LoginSuccessHandler.java 45 2011-10-06 09:42:07Z feigme@gmail.com $
 */
package com.iary.interfaces.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

public class LoginSuccessHandler implements AuthenticationSuccessHandler {

	private String successUrl;

	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		String from = request.getParameter("from");
		if(StringUtils.isNotBlank(from)){
			response.sendRedirect(from);
		}else{
			response.sendRedirect(request.getContextPath() + successUrl);
		}
	}

	public String getSuccessUrl() {
		return successUrl;
	}

	public void setSuccessUrl(String successUrl) {
		this.successUrl = successUrl;
	}

}
